package org.zsl.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zsl.model.Product;
import org.zsl.service.ProductService;

@RestController
@RequestMapping("/pro")
@CrossOrigin
public class ProductController {

    @Autowired
    private ProductService service;

    @RequestMapping("/list")
    public  String getAll(){

         return JSON.toJSONString(service.getAll());
    }

    @GetMapping("/get")
    public String getProducts(Product product){
      return JSON.toJSONString(service.getProductsByExample(product))  ;
    }

    @PostMapping("/instock")
    public String inStock(Integer productId,Integer quantity){

        return   JSON.toJSONString( service.inStock(productId,quantity));
    }

}
